package indexer;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public abstract class IndexerFileReader {
	protected abstract String[] processFile(File file);
	
	protected static final String unicodeCharacters;
	
	static {
		// Obtengo los caracteres especiales UNICODE que
		// no se quiere eliminar del texto
		StringBuilder unicodes = new StringBuilder();
		for (int i = 192; i < 255; i++) {
			unicodes.append((char)i);
		}
		unicodeCharacters = unicodes.toString();
	}

	protected String getFileText(File file) throws FileNotFoundException, IOException {
		StringBuilder fileText = new StringBuilder("");
		BufferedReader br = new BufferedReader(new FileReader(file));
		String line = null;
		while ((line = br.readLine()) != null) {
			fileText.append(line);
			fileText.append(System.getProperty("line.separator"));
		}
		br.close();
		return fileText.toString();
	}

	/**
	 * This method process the text of a file, identifying and extracting each word from
	 * it.
	 * @return word, the word read from the file
	 */
	protected abstract String[] parseWord();
}
